﻿package 
{
    import cn.snowkit.uitls.*;
    import com.tudou.home.*;
    import com.tudou.home.model.*;
    import com.tudou.home.model.ad.*;
    import com.tudou.js.*;
    import com.tudou.log.*;
    import com.tudou.utils.*;
    import flash.display.*;
    import flash.events.*;
    import flash.system.*;
    import flash.utils.*;

    public class TudouVideoPlayer_Homer extends Sprite
    {
        private var versionXml:Class;
        private var checkTimer:Timer;
        public static const VERSION:String = "土豆主站 V1.7.@release.@build";

        public function TudouVideoPlayer_Homer()
        {
            versionXml = TudouVideoPlayer_Homer_versionXml;
            Security.allowDomain("*");
            VersionUtil.setRightMenu(versionXml, this, VERSION);
            this.loaderInfo.addEventListener(Event.INIT, inited);
            this.addEventListener(Event.ADDED_TO_STAGE, addToStageHlr);
            return;
        }// end function

        private function initLogger() : void
        {
            var _loc_4:String = null;
            var _loc_1:* = PageInfo.getInstance().urlParams;
            TudouLogger.level = _loc_1["log"];
            TudouLogger.addLogger(Logger.getInst());
            var _loc_2:Object = {player:PlayerProxy, jscall:JSCall, v2:V2Proxy, ad:AdInfoProxy};
            var _loc_3:* = String(_loc_1["loglist"]).split(",");
            if (_loc_3)
            {
                for each (_loc_4 in _loc_3)
                {
                    
                    if (_loc_2.hasOwnProperty(_loc_4))
                    {
                        TudouLogger.addLogClass(_loc_2[_loc_4]);
                    }
                }
            }
            return;
        }// end function

        private function initFacade() : void
        {
            PlayerFacade.geInstance().start(this);
            return;
        }// end function

        private function checkStageSize() : void
        {
            if (this.stage.stageWidth > 0 && this.stage.stageHeight > 0)
            {
                initFacade();
            }
            else
            {
                checkTimer = new Timer(20);
                checkTimer.addEventListener(TimerEvent.TIMER, checkStageSizeHlr);
                checkTimer.start();
            }
            return;
        }// end function

        private function checkStageSizeHlr(event:TimerEvent) : void
        {
            if (this.stage.stageWidth > 0 && this.stage.stageHeight > 0)
            {
                checkTimer.stop();
                checkTimer.removeEventListener(TimerEvent.TIMER, checkStageSizeHlr);
                checkTimer = null;
                initFacade();
            }
            return;
        }// end function

        private function addToStageHlr(event:Event) : void
        {
            this.removeEventListener(Event.ADDED_TO_STAGE, addToStageHlr);
            FullScreen.getInst().init(stage);
            return;
        }// end function

        private function inited(event:Event) : void
        {
            Logger.getInst().debug(this, "inited: ", getTimer());
            var _loc_2:* = this.root.loaderInfo.parameters;
            PageInfo.getInstance().collect(_loc_2, this.root.loaderInfo.url);
            initLogger();
            checkStageSize();
            return;
        }// end function

    }
}
